<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta charset="UTF-8">
		<title>Title</title>
		<link rel="stylesheet" href="../../../component/pear/css/pear.css" />
	</head>
	<body>
		<form class="layui-form" action="">
			<div class="mainBox">
				<div class="main-container" id="main-container">
				</div>
			</div>

			<script type="text/html" id="tpl">
				<div class="main-container">
					<div class="layui-form-item">
						<label class="layui-form-label">手机号</label>
						<div class="layui-input-block">
							{{ d.phone }} ,,,{{d.stype}}
						</div>
					</div>
			 
					{{# layui.each(d.ques,function(index,item){ }}
					<ul>
						<li><pre>{{ item.title }}</pre></li>
						<li><pre>{{ item.option2 }}</pre></li>
						<li><pre>{{ item.option3 }}</pre></li>
						<li><pre>{{ item.option4 }}</pre></li> 
						<li>选择的是 {{ item.choice }}</li>
					</ul>

					{{# })  }}
				</div>
			</script>

			<div class="bottom">
				<div class="button-container">
					<button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
						lay-filter="user-save">
						<i class="layui-icon layui-icon-ok"></i>
						提交
					</button>
					<button type="reset" class="pear-btn pear-btn-sm">
						<i class="layui-icon layui-icon-refresh"></i>
						重置
					</button>
				</div>
			</div>
		</form>
		<script src="../../../component/layui/layui.js"></script>
		<script src="../../../component/pear/pear.js"></script>
		<script>
			layui.use(['form', 'jquery', 'laydate', 'laytpl'], function() {
				var BASE_URL = "/shengyin/";
				var survey = {};
				let form = layui.form;
				let $ = layui.jquery;
				let laytpl = layui.laytpl;
				let id = window.sessionStorage.getItem("id");
				$.get(window.BASEPATH + "survey/preview/" + id, function(res) {
					if (res.code != 0) {
						alert(res.msg);
						return;
					}
					survey = res.data;
					var getTpl = $('#tpl').html();
					laytpl(getTpl).render(survey, function(html) {
						$('#main-container').html(html);
					});
				});


				form.on('submit(user-save)', function(data) {
					$.ajax({
						url: BASE_URL + "survey/generate/" + data.field.stype,
						//data:JSON.stringify(data.field),
						type: "get",
						dataType: 'json',
						contentType: 'application/json',
						success: function(result) {
							if (result.code == 0) {
								layer.msg(result.msg, {
									icon: 1,
									time: 1000
								}, function() {
									parent.layer.close(parent.layer.getFrameIndex(window
										.name)); //关闭当前页
									parent.layui.table.reload("user-table");
								});
							} else {
								layer.msg(result.msg, {
									icon: 2,
									time: 2000
								});
							}
						},
						error: function(e) {
							layer.msg(e, {
								icon: 2,
								time: 2000
							});
						}
					});

					// $.post(BASE_URL+"suser/add",data.field,function(result){
					// 	//alert(JSON.stringify(result));
					// 	if(result.code==0){
					// 	    layer.msg(result.msg,{icon:1,time:1000},function(){
					// 	        parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
					// 	        parent.layui.table.reload("user-table");
					// 	    });
					// 	}else{ 
					// 	    layer.msg(result.msg,{icon:2,time:2000});
					// 	}
					// }).error(function(e){
					// 	layer.msg(e,{icon:2,time:2000});
					// });
					return false;
				});
			})
		</script>
		<script>
		</script>

	</body>
</html>
